import { formatFileSize } from "@/utils/tools";
export function fileToBase64Url(file: any, callback: any) {
  var reader = new FileReader();
  reader.onload = function (e: any) {
    callback(e.target.result);
  };
  reader.readAsDataURL(file);
}
export function base64UrlToFile(base64Url: string, filename: string) {
  filename = filename || "test.png";
  let mime = "image/png";
  var bstr = atob(base64Url.replace(/^data:image\/(png|jpeg|jpg);base64,/, ""));
  var n = bstr.length;
  var u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new File([u8arr], filename, { type: mime });
}
export const beforeUpload = (file: any) => {
  const limit = 5 * 1024 * 1024;
  if (file.size > limit) {
    message.error(
      `${$t("placeholder155")}${formatFileSize(limit, 0)}`
    );
    return false;
  }
  return true;
};
